#include <iostream>
using namespace std;

long long int result(long long int a,long long int b,long long int n)
{
	long int result1;
	switch (n)
	{
		case 0:return a;break;
		case 1:return b;break;
		default:break;
	}
	for (int i=2;i<=n;i++)
	{
		result1=(a*b)%10000007;
		a=b;
		b=result1;
	}
	return b;
}

void main ()
{
	long long int a,b,n;
	while (scanf ("%I64d%I64d%I64d",&a,&b,&n)!=EOF)
	{
		printf ("%I64d\n",result (a,b,n));
	}

}